import moment from 'moment';
import {ACCESS_TOKEN} from '@/store/mutation-types'

const common = {
    methods: {
        /**
         * 根据关键词获取CRM选项列表
         * @param keywords
         * @param withEmpty
         * @param module
         * @returns {*}
         * @private
         */
        __fetchCrmOptionsByKeywords(keywords, withEmpty = false, module='sale') {
            let url = `/${module}/api/option/keywords/${keywords}`;
            return this.$http.get(url, {
                params: {withEmpty: withEmpty ? 1 : 0}
            });
        },
        /**
         * 设置时间组件可选范围
         */
        __disabledDateBeforeCurrent(current) {
            // Can not select days before today and today
            return current && current < moment().endOf('day');
        },
    
        /**
         * 路由参数
         * @param key
         * @returns {*}
         * @private
         */
        __getParam(key) {
            return this.$route.params[key];
        },
        
        /**
         * 路由query
         * @param key
         * @returns {*}
         * @private
         */
        __getQuery(key) {
            return this.$route.query[key];
        },
    
        /**
         *  异常提示
         * @param content
         * @param title
         * @private
         */
        __alertResponseException(content, title = '错误提示') {
            this.$notification.error({
                message: title,
                description: content,
                duration: 4
            });
        },
    
        /**
         * 获取当前登录用户ID
         * @returns {number}
         * @private
         */
        __getCurrentUserPk () {
            return 1;
        },
    
        /**
         * 获取成员列表
         *
         * @returns {*}
         * @private
         */
        __fetchMemberLists () {
            return this.$http.get('/organize/api/member');
        },
    
        /**
         * @private
         */
        __init_detail (id) {},
    
        /**
         * 跳转
         * @param route
         * @private
         */
        __redirectTo (route) {
            return this.$router.push(route);
        },
    
        /**
         * 获取公共上传接口地址
         * @param fill
         * @returns {string}
         * @private
         */
        __systemUploadAction(fill=1) {
            return `${process.env.VUE_APP_DOMAIN}/system/api/upload?fill=${fill}`;
        },
    
        /**
         * 获取公共上传请求头
         * @returns {{Authorization: string}}
         * @private
         */
        __systemUploadHeaders() {
            return {
                Authorization: 'Bearer ' + this.$ls.get(ACCESS_TOKEN)
            }
        },
    },
    
    watch: {
        '$route.params.id'(val, old) {
            if( val ) {
                this.id = val;
                this.__init_detail(val);
            }
        }
    }
};


export {common}